#!/usr/bin/python

print "Content-Type: text/html\n"
import os, random, cgi, cgitb
cgitb.enable()
i = 0
c=0
richtig = 0
erg = 0
a= random.randint(1,11)
b= random.randint(1,11)
form = cgi.FieldStorage()
if "i" in form: i = int(form["i"].value)
if "erg" in form: erg = int(form["erg"].value)
if "c" in form: c = int(form["c"].value)
if "richtig" in form: richtig = int(form["richtig"].value)
print "<html>"
print "<head><title>Kopfrechner</title></head>"
print '<form action="kopfrechentrainer.cgi" method="POST">'
#print '<form action="kopfrechentrainer.cgi" method="GET">'
print "<p>"
if(i!=0):
    if c == erg:
        richtig+=1
if i<6:
    print "Loesen sie bitte folgende Aufgabe:"
    if i<3:
        print a,"+",b,"= ?"
        c = a+b
        i+=1
    else:
        print a,"*",b,"= ?"
        c = a*b
        i+=1
else:
    print "Sie haben ",richtig,"von",i," Aufgaben richtig."


if i <=6: 
    print '<br/>Ihre eingabe: <input type="text" name="erg">'
    print '<input type="hidden" name="i" value=',i,'>'
    print '<input type="hidden" name="c" value=',c,'>'
    print '<input type="hidden" name="richtig" value=',richtig,'>'
    print '<input type="submit" name="ok" value="ok">'
print "</p>"
print "</html>"
